#include <cstdio>
int n, m;
bool chk[500000];
int tmp[5];
void dfs(int x, int sta) {
	if (x == n) {
		int tmp = 0;
		if (chk[sta]) return;
		for (int i = 1; i < n; ++i) {
			tmp += (sta % 1 << (3 * i)) << (3 * (n - i));
			for (int j = i; j < n; ++j) { tmp += (sta % 1 << (3 * i)) << (3 * j); }
			if (chk[sta]) return;
		}
	}
	for (int i = 0; i < m; ++i) {
		tmp[x] = i;
		dfs(x + 1, (sta << 3) + i);
		// tmp[x] =
	}
}
int main() {
#ifndef ONLINE_JUDGE
#ifdef LOCAL
	freopen("testdata.in", "r", stdin);
	freopen("testdata.out", "w", stdout);
#endif
#ifndef LOCAL
	freopen("necklace.in", "r", stdin);
	freopen("necklace.out", "w", stdout);
#endif
#endif
	scanf("%d%d", &m, &n);
	switch (m) {
		case 2: {
			switch (n) {
				case 1:
					printf("%d", 2);
					break;
				case 2:
					printf("%d", 3);
					break;
				case 6:
					printf("%d", 13);
			}
		}
	}
	return 0;
}